﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 学生成绩管理系统
{
    public partial class Frmcjgl : Form
    {
        public static Frmcjgl frmcjgl = null;

        public Frmcjgl()
        {
            InitializeComponent();
            UserInfoData data = new UserInfoData();
            //获取登录用户的姓名
            //这里username为空，先把值传过来简单方法
           // data.Userid = Constants.Username;
            data.Userid = Login.name;
            DataSet ds = UserInfoOperation.getUserInfoAll(data);
            if(ds.Tables[0].Rows.Count>0)
            {//获取登录用户的身份
                Constants.Userlevel = ds.Tables[0].Rows[0]["用户权限"].ToString();
                if(Constants.Userlevel=="学生")
                { //登录身份是“学生”，设置某些模块不可被调用
                    MenuItemyhcx.Enabled = false;//系统管理
                    MenuItembjxxtj.Enabled = false;//班级信息添加
                    MenuItemcjsc.Enabled = false;//成绩删除
                    MenuItemcjxg.Enabled = false;//成绩修改
                    MenuItemjsxxcx.Enabled = false;//教师信息查询
                    MenuItemjsxxtj.Enabled = false;//教师信息添加
                    MenuItemjsxxsc.Enabled = false;//教师信息删除
                    MenuItemjsxxxg.Enabled = false;//教师信息修改
                    MenuItemkcbsc.Enabled = false;//课程表删除
                    MenuItemkcbtj.Enabled = false;//课程表添加
                    MenuItemkcbxg.Enabled = false;//课程表修改
                    MenuItemkcxxsc.Enabled = false;//课程信息删除
                    MenuItemkcxxtj.Enabled = false;//课程信息添加
                    MenuItemkcxxxg.Enabled = false;//课程信息修改
                    MenuItemsjkbf.Enabled = false;//数据库备份
                    MenuItemsjkhf.Enabled = false;//数据库恢复
                    MenuItemxsxxcx.Enabled = false;//学生信息查询
                    MenuItemxsxxtj.Enabled = false;//学生信息添加
                    MenuItemxsxxxg.Enabled = false;//学生信息修改
                    MenuItemyhsc.Enabled = false;//用户删除
                    MenuItemyhtj.Enabled = false;//用户添加
                    MenuItemyhxg.Enabled = true;//用户修改
                    MenuItemzyxxxg.Enabled = false;//专业信息修改
                    MenuItemzyxxtj.Enabled = false;//专业信息添加
                    MenuItemzyxxsc.Enabled = false;//专业信息删除
                    MenuItembjxxsc.Enabled = false;//班级信息删除
                    MenuItembjxxxg.Enabled=false;//班级信息修改
                }
                else if (Constants.Userlevel == "任课教师")
                {//登录身份是“任课教师”，设置某些模块不可被调用
                    this.MenuItembjxxtj.Enabled = false;//班级信息添加
                    this.MenuItembjxxxg.Enabled = false;//班级信息修改
                    this.MenuItemcjxg.Enabled = false;//成绩修改
                    this.MenuItemcjsc.Enabled = false;//成绩删除
                    this.MenuItemcjgl.Enabled = true;//成绩管理
                    this.MenuItemjsxxcx.Enabled = true;//教师信息查询
                    this.MenuItemjsxxsc.Enabled = false;//教师信息删除
                    this.MenuItemjsxxtj.Enabled = false;//教师信息添加
                    this.MenuItemjsxxxg.Enabled = false;//教师信息修改
                    this.MenuItemkcbsc.Enabled = false;//课程表删除
                    this.MenuItemkcbtj.Enabled = false;//课程表添加
                    this.MenuItemkcbxg.Enabled = false;//课程表修改
                    this.MenuItemsjkbf.Enabled = false;//数据库备份
                    this.MenuItemsjkhf.Enabled = false;//数据库恢复
                    this.MenuItemxsxxxg.Enabled = false;//学生信息修改
                    this.MenuItemxsxxsc.Enabled = false;//学生信息删除
                    this.MenuItemxsxxtj.Enabled = false;//学生信息添加
                    this.MenuItemxsxxgl.Enabled = true;//学生信息管理
                    this.MenuItemxsxxcx.Enabled = true;//学生信息查询
                    this.MenuItemyhsc.Enabled = false;//用户管理
                    this.MenuItemyhtj.Enabled = false;//用户添加
                    this.MenuItemyhxg.Enabled = true;//用户修改
                    this.MenuItemzyxxtj.Enabled = false;//专业信息添加
                    this.MenuItemzyxxsc.Enabled = false;//专业信息删除
                    this.MenuItemzyxxxg.Enabled = false;//专业信息修改
                    this.MenuItembjxxsc.Enabled = false;//班级信息删除
                    this.MenuItembjgl.Enabled = false;//班级信息管理
                }
                else
                {
                    this.MenuItembjxxtj.Enabled = true;//班级信息添加
                    this.MenuItembjxxxg.Enabled = true;//班级信息修改
                    this.MenuItemcjsc.Enabled = true;//成绩删除
                    this.MenuItemcjgl.Enabled = true;//成绩管理
                    this.MenuItemcjxg.Enabled = true;//成绩修改
                    this.MenuItemjsxxcx.Enabled = true;//教师信息查询
                    this.MenuItemjsgl.Enabled = true;//教师信息管理
                    this.MenuItemjsxxsc.Enabled = true;//教师信息删除
                    this.MenuItemjsxxxg.Enabled = true;//教师信息修改
                    this.MenuItemkcbsc.Enabled = true;//课程表删除
                    this.MenuItemkcbtj.Enabled = true;//课程表添加
                    this.MenuItemkcbxg.Enabled = true;//课程表修改
                    this.MenuItemkcxxsc.Enabled = true;//课程信息删除
                    this.MenuItemkcxxtj.Enabled = true;//课程信息添加
                    this.MenuItemkcxxxg.Enabled = true;//课程信息修改
                    this.MenuItemsjkbf.Enabled = true;//数据库备份
                    this.MenuItemsjkhf.Enabled = true;//数据库恢复
                    this.MenuItemxsxxgl.Enabled = true;//学生信息管理
                    this.MenuItemxsxxsc.Enabled = true;//学生信息删除
                    this.MenuItemxsxxtj.Enabled = true;//学生信息添加
                    this.MenuItemxsxxxg.Enabled = true;//学生信息修改
                    this.MenuItemyhsc.Enabled = true;//用户删除
                    this.MenuItemyhxg.Enabled = true;//用户修改
                    this.MenuItemyhtj.Enabled = true;//用户添加
                    this.MenuItemzyxxtj.Enabled = true;//专业信息添加
                    this.MenuItemzyxxsc.Enabled = true;//专业信息删除
                    this.MenuItemzyxxxg.Enabled = true;//专业信息修改
                    this.MenuItembjxxsc.Enabled = true;//班级信息删除
                    this.MenuItembjxxtj.Enabled = true;//班级信息添加
                }
            }
        }
        //Constants类：
        public class Constants
        {
            private static string username = "";
            private static string userlevel = "";
            public static string Username//获取用户名
            {
                get { return username; }
                set { username = value; }
            }
            public static string Userlevel
            {
                get { return userlevel; }
                set { userlevel = value; }
            }

        }
        //UserInfoData类：
        public class UserInfoData
        {
            private string userid = "";
            private string userpwd = "";
            private string userlevel = "";
            //登录用户名
            public string Userid
            {
                get { return userid; }
                set { userid = value; }
            }
            //登录用户密码
            public string Userpwwd
            {
                get { return userpwd; }
                set { userpwd = value; }
            }
            //登录用户身份
            public string Userlevel
            {
                get { return userlevel; }
                set { userlevel = value; }

            }
        }
        //UserInfoOperation类
        public class UserInfoOperation
        {
            private static DataAccess dataAccess = new DataAccess();
            public static bool insertUserInfo(UserInfoData data)
            {
                //数据插入
                string sql = "insert into 用户表(用户名，用户密码，用户权限) values(" +
                    "'" + data.Userid + "'," + "'" + data.Userpwwd + "'," +
                    "'" + data.Userlevel + "')";
                return dataAccess.ExecuteSQL(sql);
            }
            public static bool updateUserInfo(UserInfoData Data)
            {//数据修改
                string sql = "Update 用户表 set 用户密码='" + Data.Userpwwd
                + "'/," + "用户权限='" + Data.Userlevel + "'" +
                "where 用户名='" + Data.Userid + "'";
                return dataAccess.ExecuteSQL(sql);

            }
            public static bool deleteUserInfo(string userid)
            {//数据删除
                string sql = String.Format("delete 用户表 where 用户名='{0}'",userid);
                return dataAccess.ExecuteSQL(sql);
            }
            public static DataSet getUserInfo(UserInfoData data)
            {//数据查询
                string condition = "";
                if (data.Userid != null && data.Userid != "")
                {
                    condition += " and 用户名='" + data.Userid + "'";
                }
                if (data.Userlevel != null && data.Userlevel != "")
                {
                    condition += "and 用户权限='" + data.Userlevel + "'";
                }
                string sql = "select 用户名,用户权限 from 用户表 where 1=1"+
                    condition;
                return dataAccess.GetDataSet(sql,"用户表");
            }
            //getUserInfoAll
            public static DataSet getUserInfoAll(UserInfoData data)
            {//数据查询
            string condition = "";//查询的条件
            if(data.Userid!=null&&data.Userid!="")
            {
                condition += " and 用户名='" + data.Userid + "'";
            }
            if(data.Userlevel!=null&& data.Userlevel!="")
            {
                condition += " and 用户权限='" + data.Userlevel + "'";
            }
            string sql = "select 用户名,用户密码,用户权限 from 用户表 where 1=1" + condition;
            return dataAccess.GetDataSet(sql,"用户表");
        }
        }

        private void MenuItembzzt_Click(object sender, EventArgs e)
        {//调出帮助主题模块
            Help.ShowHelp(this, @"E:\sqlserver\学生成绩管理系统\学生成绩管理系统\help.chm");
        }

        private void MenuItemtc_Click(object sender, EventArgs e)
        {//退出项目文件
            this.Close();
        }
        //这个方法
        private void MenuItemyhxg_Click(object sender, EventArgs e)
        {//调出用户修改模块
            Frmmmxy objchild = new Frmmmxy(); 
            objchild.MdiParent = this;
            objchild.Show();
        }

        private void MenuItemctcd_Click(object sender, EventArgs e)
        {//实现窗体层叠
            this.LayoutMdi(MdiLayout.Cascade);
        }

        private void MenuItemgy_Click(object sender, EventArgs e)
        {//实现关于版本的信息
            MessageBox.Show("学生成绩管理系统v1.0","版权信息",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
        }

        private void MenuItemlxwm_Click(object sender, EventArgs e)
        {//实现联系我们
            System.Diagnostics.Process.Start(@"mailto:abc@18cen.com");
        }

        private void MenuItemjszc_Click(object sender, EventArgs e)
        {//实现技术支持
            System.Diagnostics.Process.Start("http://topic.csdn.net/");
        }

        private void MenuItemsppp_Click(object sender, EventArgs e)
        {//实现窗体水平平铺
            this.LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void MenuItemczpp_Click(object sender, EventArgs e)
        {//实现窗体垂直平铺
            this.LayoutMdi(MdiLayout.TileVertical);
        }

        private void MenuItemcjcx_Click(object sender, EventArgs e)
        {//调出成绩查询模块
            Frmcjcx frmcjcx = new Frmcjcx();
            frmcjcx.MdiParent = this;
            frmcjcx.Show();
        }

        private void MenuItemsjlr_Click(object sender, EventArgs e)
        {//调出成绩添加模块
            frmadda frmaddcj = new frmadda();
            frmaddcj.MdiParent = this;
            frmaddcj.Show();
        }

        private void MenuItemcjxg_Click(object sender, EventArgs e)
        {//调出成绩修改摸块
            Frmcjcx frmmodcj = new Frmcjcx("mod");
            frmmodcj.MdiParent = this;
            frmmodcj.Show();
        }

        private void MenuItemcjsc_Click(object sender, EventArgs e)
        {//调出成绩删除模块
            Frmcjcx frmdelcj = new Frmcjcx("del");
            frmdelcj.MdiParent = this;
            frmdelcj.Show();
        }

        private void MenuItemzyxxcx_Click(object sender, EventArgs e)
        {//调出专业信息查询模块
            Frmzyxxcx zyxxcx = new Frmzyxxcx("");
            zyxxcx.MdiParent = this;
            zyxxcx.Show();
        }

        private void MenuItemzyxxtj_Click(object sender, EventArgs e)
        {//调出专业信息添加模块
            Frmaddzyxx addzyxx = new Frmaddzyxx("");
            addzyxx.MdiParent = this;
            addzyxx.Show();
        }

        private void MenuItemzyxxxg_Click(object sender, EventArgs e)
        {//专业信息修改模块
            Frmzyxxcx zyxxcx = new Frmzyxxcx("mod");
            zyxxcx.MdiParent = this;
            zyxxcx.Show();
        }

        private void MenuItemzyxxsc_Click(object sender, EventArgs e)
        {//调出班级信息查询模块
            Frmzyxxcx zyxxcx = new Frmzyxxcx("del");
            zyxxcx.MdiParent = this;
            zyxxcx.Show();
        }

        private void MenuItembjxxcx_Click(object sender, EventArgs e)
        {//调出班级信息查询模块
            Frmbjxxcx bjxxcx = new Frmbjxxcx("");
            bjxxcx.MdiParent = this;
            bjxxcx.Show();
        }

        private void MenuItembjxxtj_Click(object sender, EventArgs e)
        {//班级信息添加模块
            Frmaddclass addbjxx = new Frmaddclass("");
            addbjxx.MdiParent = this;
            addbjxx.Show();
        }

        private void MenuItembjxxsc_Click(object sender, EventArgs e)
        {//调出班级信息删除模块
            Frmbjxxcx bjxxcx = new Frmbjxxcx("del");
            bjxxcx.MdiParent = this;
            bjxxcx.Show();
        }

        private void MenuItembjxxxg_Click(object sender, EventArgs e)
        {//调出班级信息修改模块
            Frmbjxxcx bjxxcx = new Frmbjxxcx("mod");
            bjxxcx.MdiParent = this;
            bjxxcx.Show();
        }

        private void MenuItemxsxxcx_Click(object sender, EventArgs e)
        {//调出学生信息查询模块
            Frmstuxxcx stucx = new Frmstuxxcx("");
            stucx.MdiParent = this;
            stucx.Show();
        }

        private void MenuItemxsxxtj_Click(object sender, EventArgs e)
        {//调出学生信息添加模块
            Frmaddstudent stucx = new Frmaddstudent("");
            stucx.MdiParent = this;
            stucx.Show();
        }

        private void MenuItemxsxxxg_Click(object sender, EventArgs e)
        {//调出学生信息修改模块
            Frmstuxxcx stuxxcx = new Frmstuxxcx("mod");
            stuxxcx.MdiParent = this;
            stuxxcx.Show();
        }

        private void MenuItemxsxxsc_Click(object sender, EventArgs e)
        {//调出学生信息删除模块
            Frmstuxxcx stuxxcx = new Frmstuxxcx("del");
            stuxxcx.MdiParent = this;
            stuxxcx.Show();

        }

        private void MenuItemyhtj_Click(object sender, EventArgs e)
        {//用户添加模块
            FrmaddUser addyh = new FrmaddUser();
            addyh.MdiParent = this;
            addyh.Show();
        }

        private void MenuItemkcbcx_Click(object sender, EventArgs e)
        {//课程信息查询模块
            Frmschedulecx kcbcx = new Frmschedulecx("");
            kcbcx.MdiParent = this;
            kcbcx.Show();
        }

        private void MenuItemkcbtj_Click(object sender, EventArgs e)
        {//课程信息添加模块
            Frmaddschedule addkcb = new Frmaddschedule("","","","");
            addkcb.MdiParent = this;
            addkcb.Show();
        }

        private void MenuItemjsxxcx_Click(object sender, EventArgs e)
        {//教师信息查询模块
            FrmTeacherCx jsxxcx = new FrmTeacherCx("");
            jsxxcx.MdiParent = this;
            jsxxcx.Show();
        }

        private void MenuItemkcxxxg_Click(object sender, EventArgs e)
        {//课程信息修改模块
            FrmCourseInfoCx kcxxxg = new FrmCourseInfoCx("mod");
            kcxxxg.MdiParent = this;
            kcxxxg.Show();
        }

        private void MenuItemkcxxsc_Click(object sender, EventArgs e)
        {//课程信息删除模块
            FrmCourseInfoCx kcxxsc = new FrmCourseInfoCx("del");
            kcxxsc.MdiParent = this;
            kcxxsc.Show();

        }

        private void MenuItemjsxxtj_Click(object sender, EventArgs e)
        {//教师信息添加模块

            FrmaddTeacher addjsxx = new FrmaddTeacher("");
            addjsxx.MdiParent = this;
            addjsxx.Show();
        }

        private void MenuItemjsxxxg_Click(object sender, EventArgs e)
        {//教师信息修改模块
            FrmTeacherCx jsxxcx = new FrmTeacherCx("mod");
            jsxxcx.MdiParent = this;
            jsxxcx.Show();
        }

        private void MenuItemjsxxsc_Click(object sender, EventArgs e)
        {//教师信息删除模块
            FrmTeacherCx jsxxcx = new FrmTeacherCx("del");
            jsxxcx.MdiParent = this;
            jsxxcx.Show();
        }

        private void MenuItemkcxxcx_Click(object sender, EventArgs e)
        {//课程信息查询模块
            FrmCourseInfoCx kcxxcx = new FrmCourseInfoCx("");
            kcxxcx.MdiParent = this;
            kcxxcx.Show();
        }

        private void MenuItemkcxxtj_Click(object sender, EventArgs e)
        {//课程信息添加模块
            FrmaddCourseInfo addkcxx = new FrmaddCourseInfo("");
            addkcxx.MdiParent = this;
            addkcxx.Show();

        }

        private void MenuItemkcbxg_Click(object sender, EventArgs e)
        {//课程表修改模块
            Frmschedulecx kcbxg = new Frmschedulecx("mod");
            kcbxg.MdiParent = this;
            kcbxg.Show();

        }

        private void MenuItemkcbsc_Click(object sender, EventArgs e)
        {
            Frmschedulecx kcbxg = new Frmschedulecx("del");
            kcbxg.MdiParent = this;
            kcbxg.Show();
        }

        private void MenuItemyhcx_Click(object sender, EventArgs e)
        {//调出用户查询模块
            Frmusercx usercx = new Frmusercx("");
            usercx.MdiParent = this;
            usercx.Show();

        }

        private void MenuItemyhgl_Click(object sender, EventArgs e)
        {//用户管理模块
            //FrmaddUser adduser = new FrmaddUser();
            //adduser.MdiParent = this;
            //adduser.Show();
        }

        private void MenuItemyhsc_Click(object sender, EventArgs e)
        {//用户删除模块
            Frmusercx usercx = new Frmusercx("del");
            usercx.MdiParent = this;
            usercx.Show();
        }

        private void MenuItemcxdl_Click(object sender, EventArgs e)
        {
            //重新登录模块
            Login login = new Login();
            login.ShowDialog();
        }

        private void MenuItemsjkbf_Click(object sender, EventArgs e)
        {//数据库备份模块

        }

        private void MenuItemsjkhf_Click(object sender, EventArgs e)
        {
           //数据库恢复模块
        }

        //避免对话框显示关闭时显示两次
        private Boolean b = false;
        private void Frmcjgl_FormClosing(object sender, FormClosingEventArgs e)
        {

            if (b||MessageBox.Show("是否退出系统", "退出系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                b = true;
                Application.Exit();
            }
            else
            {
                b = false;
                e.Cancel = true;
            }
        }

        private void Frmcjgl_Load(object sender, EventArgs e)
        {

        }
    }
}